package com.mixsmart.commonweb.upload.classify;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.mixsmart.commonweb.upload.ClassifyModel;
import com.mixsmart.core.config.SystemConfig;
import com.mixsmart.utils.StringUtils;


/**
 * 按日期格式归类
 * @author lmq
 * @version 1.0
 * @since JDK1.6以上
 * <br />
 * 2016年7月22日
 */
@Component
public class DateFormatClassify extends AbstractUploadClassify {
	
	private SimpleDateFormat dateFormat = null;
	
	@Override
	public String getName() {
		return "date_format";
	}
	
	@Override
	protected String classify(ClassifyModel classifyModel) {
		String dateFormatStr = SystemConfig.getInstance().getValue("upload.classify.date.formater");
		dateFormatStr = StringUtils.isEmpty(dateFormatStr)?"yyyyMMdd":dateFormatStr;
		dateFormat = (null == dateFormat)?new SimpleDateFormat(dateFormatStr):dateFormat;
		return dateFormat.format(new Date());
	}
	
}
